#include <stdarg.h>
#include <stddef.h>
#include <linux/kernel.h>

extern int vsprintf(char *buf, const char *fmt, va_list args);

static char buf[1024];

char* __strtok = 0;

int printk(const char *fmt, ...)
{
	va_list args;
	int i;

	va_start(args, fmt);
	i = vsprintf(buf, fmt, args);
	va_end(args);
	__asm__("push %%fs\n\t"
		"push %%ds\n\t"
		"pop %%fs\n\t"
		"pushl %0\n\t"
		"pushl $buf\n\t"
		"pushl $0\n\t"
		"call tty_write\n\t"
		"addl $8, %%esp\n\t"
		"popl %0\n\t"
		"pop %%fs"
		::"r"(i) :"ax","cx","dx");

	return i;
}

void panic(const char* s)
{
	printk("Kernel panic: %s\n\r", s);
	for (;;);
}

int My_Print(const char* fmt, ...)
{
	va_list args;
	int i;

	va_start(args, fmt);
	i = vsprintf(buf, fmt, args);
	va_end(args);
	__asm__("push %%fs\n\t"
		"push %%ds\n\t"
		"pop %%fs\n\t"
		"pushl %0\n\t"
		"pushl $buf\n\t"
		"pushl $0\n\t"
		"call tty_write\n\t"
		"addl $8, %%esp\n\t"
		"popl %0\n\t"
		"pop %%fs"
		::"r"(i):"ax","cx","dx");
	return i;
}